$startdate=date

function getFolderSize([string]$folderName){
    $subFolderItems = (Get-ChildItem $folderName -recurse | Measure-Object -property length -sum)
    $FileSize="{0:N2}" -f ($subFolderItems.sum / 1GB)
    $Unit="GB"
    if($FileSize -lt 1)
    {
        $FileSize="{0:N2}" -f ($subFolderItems.sum / 1MB)
        $Unit="MB"
    }
    write-host $folderName  " -- "  $FileSize $Unit -fore green
    return $subFolderItems.sum
}


function getSubDirs2([string]$filepath){
    $colItems = (Get-ChildItem $filepath | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
    $sum=0.0
    foreach ($i in $colItems) {
       $dirsize=getFolderSize($i.FullName)               
       $sum=$sum+$dirsize
    }
    $FileSize="{0:N2}" -f ($sum / 1MB)
    $Unit="MB"
    write-host $filepath  " -- "  $FileSize $Unit -fore red
    return $sum
}

function getSubDirs([string]$filepath){
    
    $colItems = (Get-ChildItem $filepath | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)

    foreach ($i in $colItems) {
        $sum=0
        $sum=getSubDirs2($i.FullName)
        $subFolderItems = (Get-ChildItem $i.FullName | Where-Object {$_.PSIsContainer -eq $False}| Sort-Object | Measure-Object -property length -sum)               
        $subFolderItems
        write-host $subFolderItems.sum
        $sum=$sum+$subFolderItems.sum
        $FileSize="{0:N2}" -f ($sum / 1GB)
        $Unit="GB"
        if($FileSize -lt 1)
        {
            $FileSize="{0:N2}" -f ($sum / 1MB)
            $Unit="MB"
        }
        write-host $i.FullName  " -- "  $FileSize $Unit -fore green
    }
}
# filesize -startFolder "C:\tools"
getSubDirs -filepath "C:\Git\go"
# getFolderSize("C:\git\go")
$enddate=date
$enddate-$startdate